'use strict'
import React, {
    Component
} from 'react'
import {
    Link
} from 'react-router'

import Header from './Common/Header'
import {
    HttpService,
    getLocalTime,
    Tips
} from '../Tools'

export default class ScoreDetail extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataList: [],
            fldAverageGrade: 0
        }
    }
    componentWillMount() {
        let data = {
            jybTicket: sessionStorage.ticket,
            method: 'ajaxGetTestDetail'
        };
        if (this.props.params.classid || sessionStorage.scoreclassid)
            data.classId = this.props.params.classid || sessionStorage.scoreclassid

        if (this.props.params.tongkao == 'true') {
            data.method = 'ajaxGetTestTypeDetail'
            data.typeId = this.props.params.id
        } else {
            data.testid = this.props.params.id
        }
        HttpService.query({
            url: '/jxt-score/ajaxMobileScore.do',
            data,
            async: false,
            success: (res => {
                if (res.code == 0) {
                    this.setState({
                        fldAverageGrade: res.r.fldAverageGrade,
                        fldClassAvgScore: res.r.fldClassAvgScore,
                        dataList: res.r.students
                    })
                }
            })
        })
    }

    render() {
        const {
            fldAverageGrade,
            fldClassAvgScore,
            dataList
        } = this.state
        const dataTagList = dataList.map((item, index) => {
            const timeStr = getLocalTime(item.createTime)
            return (
                <ul className="score_number">
                    <li>{item.studentName}</li>
                    <li>{item.scoreIn100 || item.totalScore}</li>
                    <li>{item.classNum || item.classSort}</li>
                </ul>
            )
        })
        return (
            <div className='score_details' id={sessionStorage.userrole=='家长'?'score_details2':null}>
                <Header title='成绩排名'/>
                <div className="table_list">
                    <div className="score_table" id='pjb_scoredetail'>
                        <ul className="score_title">
                            <li>姓名</li>
                            <li>成绩</li>
                            <li>排名</li>
                        </ul>
                        {dataTagList}
                    </div>
                </div>
                <div className="footer" id='pjb_scorebottom'>
                    <span>班级平均成绩：</span>
                    <span className="mean_score">{fldAverageGrade || fldClassAvgScore}</span>
                </div>
            </div>
        )
    }
}
